package fr.red5.managers
{
	import flash.net.NetConnection;
	import flash.net.SharedObject;
	import flash.events.*;
	import flash.utils.*
	
	import fr.red5.net.Red5Connection;
	import fr.red5.utils.ArrayList;
	import fr.red5.managers.events.UserEvent;
	import fr.red5.events.SharedObjectEvent;
	import fr.red5.net.so.RemoteSharedObject;
	import fr.red5.vo.ClientVO;
	
	
	public class UserManager extends EventDispatcher
	{
		private var so:RemoteSharedObject;
		
		public static const USER_JOIN:String = "USER_JOIN";
		public static const USER_LEAVE:String = "USER_LEAVE";
		
        public var users:ArrayList;
            		
		public function UserManager(r5:Red5Connection){
			so = r5.getSharedObject("user_manager");
			so.addEventListener(SharedObjectEvent.UPDATE, onUpdate);
			so.addEventListener(SharedObjectEvent.DELETE, onDelete);
			users = new ArrayList();
		}
		
		public function onUpdate(event:SharedObjectEvent):void {
			trace("UPDATE >> name : "+ event.name+" value : "+ ClientVO(event.value)+" oldValue : "+ event.oldValue);
		}
		
		public function onDelete(event:SharedObjectEvent):void {
			trace("DELETE >> name : "+ event.name+" value : "+ ClientVO(event.value));
		}		
		/*
		public function userJoined(newID:uint,username:String):void{
			var event:UserEvent = new Event(USER_JOIN,false,false,newID,username);
			dispatchEvent(event);
		}
		
		public function userLeaved(oldId:uint,username:String):void{
			var event:UserEvent = new Event(USER_LEAVE,false,false,oldId,username);
			dispatchEvent(event);			
		}
		*/
				
	}
}